package com.liner.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liner.vo.BarResultVo;
import com.liner.vo.BarValueVo;
import com.liner.vo.BarVo;
import com.liner.entity.OrderDetail;
import com.liner.mapper.OrderDetailMapper;
import com.liner.service.OrderDetailService;
import com.liner.utils.EChartsColorUtil;
import com.liner.vo.BasicLineResultVo;
import com.liner.vo.BasicLineVo;
import com.liner.vo.StackedLineInnerVo;
import com.liner.vo.StackedLineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单详情表 服务实现类
 * </p>
 *
 * @author liner
 * @since 2022-12-03
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Override
    public BarVo barData() {
        List<BarResultVo> barResultVos = orderDetailMapper.barData();
        List<String> names = new ArrayList<>();
        List<BarValueVo> values = new ArrayList<>();

        for (BarResultVo barResultVo : barResultVos) {
            names.add(barResultVo.getName());
            BarValueVo barValueVo = new BarValueVo();
            barValueVo.setValue(barResultVo.getValue());
            barValueVo.setItemStyle(EChartsColorUtil.createItemStyle(barResultVo.getValue()));
            values.add(barValueVo);
        }
        BarVo barVo = new BarVo();
        barVo.setNames(names);
        barVo.setValues(values);
        return barVo;
    }


    @Override
    public BasicLineVo basicLineData() {
        List<BasicLineResultVo> basicLineResultVoS = this.orderDetailMapper.basicLineData();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (BasicLineResultVo basicLineResultVo : basicLineResultVoS) {
            names.add(basicLineResultVo.getDate());
            values.add(basicLineResultVo.getValue());
        }
        BasicLineVo basicLineVo = new BasicLineVo();
        basicLineVo.setNames(names);
        basicLineVo.setValues(values);
        return basicLineVo;
    }

    @Override
    public StackedLineVo stackedLineData() {
        List<String> names = this.orderDetailMapper.names();
        List<String> dates = this.orderDetailMapper.dates();
        List<StackedLineInnerVo> datas = new ArrayList<>();
        for (String name : names) {
            List<Integer> data = this.orderDetailMapper.stackedData(name);
            StackedLineInnerVo Vo = new StackedLineInnerVo();
            Vo.setName(name);
            Vo.setData(data);
            datas.add(Vo);
        }
        StackedLineVo stackedLineVo = new StackedLineVo();
        stackedLineVo.setNames(names);
        stackedLineVo.setDatas(datas);
        stackedLineVo.setDates(dates);
        return stackedLineVo;
    }

}
